package com.HZNU.Controller;

import com.HZNU.spring_api.POJO.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class DeptConsumerController {
    // RestTemplate 模版可以直接调用，注册到spring中就可以了
    @Autowired
    private RestTemplate restTemplate;

    //如果做负载均衡的话，这里不可以写死，需要用变量
//    private static final String REST_URL_PREFIX = "http://localhost:8081";
    private static final String REST_URL_PREFIX = "http://HZNU-XIAODONG-SPRINGCLOUD-PROVIDER-DEPT";

    @GetMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable("id") int id){
        System.out.println(REST_URL_PREFIX+"/dept/get/"+id);
        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,Dept.class);

    }

}
